//
//  YjHealthEventChannel.m
//  zego_ktv_plugin
//
//  Created by caofuqing on 2022/9/20.
//


#import "YjHealthEventChannel.h"
static NSString *eventChannel = @"yj_ktc_event";

@interface YjHealthEventChannel ()<FlutterStreamHandler>
@property (nonatomic, strong) FlutterEventChannel *channel;
@property (nonatomic, copy) FlutterEventSink eventSink;
@end

@implementation YjHealthEventChannel
- (instancetype)initWithMessenger:(NSObject<FlutterBinaryMessenger>*)messenger {
    if (self) {
        _channel = [FlutterEventChannel eventChannelWithName:eventChannel binaryMessenger:messenger codec:[FlutterStandardMethodCodec sharedInstance]];
        [_channel setStreamHandler:self];
    }
    return self;
}


- (FlutterError * _Nullable)onCancelWithArguments:(id _Nullable)arguments {
    self.eventSink = nil;
    return nil;
}

- (FlutterError * _Nullable)onListenWithArguments:(id _Nullable)arguments eventSink:(nonnull FlutterEventSink)events {
    self.eventSink = events;
    return nil;
}

- (void)sendMessageEventChannel:(NSString *)message {
    if (self.eventSink) {
        self.eventSink(message);
    }
}

@end
